package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Coupons;
import com.fantastic.service.zjs.CouponsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/3 10:53
 * @description: 优惠券信息表请求控制器
 */
@RestController
    @RequestMapping("/coupons")
public class CouponsControllerAdmin {
    @Resource
    private CouponsService couponsService;

    /**
     * 查询优惠券信息
     *
     * @param coupons
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listCoupons")
    public ResultData listCoupons(Coupons coupons, @RequestParam(name="page",
            defaultValue = "1") int pageNum,
                                  @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Coupons> listCoupons = couponsService.listCoupons(coupons);
        PageInfo<Coupons> couponsPageInfo = new PageInfo<>(listCoupons);
        return new ResultData(RespStatusInfo.OK, couponsPageInfo);
    }

    /**
     * 查询单个优惠券信息
     *
     * @param couponId
     * @return
     */
    @GetMapping("/getCoupons")
    public ResultData getCoupons(Integer couponId) {
        return new ResultData(RespStatusInfo.OK, couponsService.getCoupons(couponId));
    }

    /**
     * 添加优惠券信息
     *
     * @param filePicture
     * @param coupons
     * @return
     */
    @PostMapping("/insertCoupons")
    public ResultData insertCoupons(MultipartFile filePicture, Coupons coupons) {
        return new ResultData(RespStatusInfo.OK, couponsService.insertCoupons(filePicture, coupons));
    }

    /**
     * 修改优惠券信息
     *
     * @param filePicture
     * @param coupons
     * @return
     */
    @PostMapping("/updateCoupons")
    public ResultData updateCoupons(MultipartFile filePicture, Coupons coupons) {
        return new ResultData(RespStatusInfo.OK, couponsService.updateCoupons(filePicture, coupons));
    }

    /**
     * 删除优惠券信息
     *
     * @param couponId
     * @return
     */
    @PostMapping("/deleteCoupons")
    public ResultData deleteCoupons(Integer couponId) {
        return new ResultData(RespStatusInfo.OK, couponsService.deleteCoupons(couponId));
    }

}
